package atom.ui.components.input 
{
	
	import atom.ui.ComponentContainer;
	import com.greensock.easing.Elastic;
	import com.greensock.TweenLite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	/**
	 * ...
	 * @author Jorge Braccini
	 */
	public class Text extends ComponentContainer {
		
		private var _tf:TextField;
		
		public function Text(init:Object=null) {
			super(init);
			
			//TODO: Font compatibility
		}
		
		override protected function initValues():void {
			super.initValues();
			
			init.fontFace 		= "Arial";
			init.width 			= 100;
			init.height 		= 40;
			init.text			= "";
			init.color			= 0x000000;
			init.bgColor		= 0xffffff;
			init.margin			= 5;
			init.selectable 	= true;
			init.mouseEnabled	= true;
		}
		
		override protected function create():void {
			_tf = new TextField();
			_tf.textColor = textColor;
			//_tf.border = true;
			
			content.addChild(_tf);
			
			super.create();
		}
		
		override protected function draw():void {
			_tf.x				= margin;
			_tf.y				= margin;
			_tf.width 			= width - (margin * 2);
			_tf.height 			= height - (margin * 2);
			_tf.textColor		= textColor;
			_tf.mouseEnabled	= init.mouseEnabled;
			
			graphics.clear();
			graphics.beginFill(bgColor);
			graphics.drawRect(0, 0, width, height);
			graphics.endFill();
		}
		
		/////////////////////////////////////////
		// Public Methods ///////////////////////
		/////////////////////////////////////////
		
		override public function update():void {
			_tf.text = text;
			_tf.selectable = selectable;
		}
		
		/////////////////////////////////////////
		// Private Methods //////////////////////
		/////////////////////////////////////////
		
		/////////////////////////////////////////
		// Properties ///////////////////////////
		/////////////////////////////////////////
		
		public function get selectable():Boolean { return init.selectable; }
		
		public function set selectable(value:Boolean):void {
			init.selectable = value;
			update();
		}
		
		public function get text():String { return init.text; }
		
		public function set text(value:String):void {
			init.text = value;
			update();
		}
		
		public function get textColor():uint { return init.textColor; }
		
		public function set textColor(value:uint):void {
			init.textColor = value;
			draw();
		}
		
		public function get bgColor():uint { return init.bgColor; }
		
		public function set bgColor(value:uint):void {
			init.bgColor = value;
			draw();
		}
		
		override public function set width(value:Number):void {
			super.width = value;
			dispatchEvent(new Event("atom_invalidate"));
		}
		
	}

}